<template>
  <div class="food" ref="homePage">
    <div class="bj">
      <van-nav-bar title="购物" left-arrow @click-left="onClickLeft" />
      </van-nav-bar>
    </div>

    <div style="width: 100%;height: 130px;"></div>
    <div class="input">
      <form action="/" style="width: 90%;">
        <van-search v-model="input" placeholder="搜索想要的旅游产品或服务"  @search="inputdata()" /><!-- @search="onSearch" -->
      </form>
    </div>
    <van-dropdown-menu active-color="#46d0ca">
      <div style="width: 1px;height: 20px;border: 1px solid rgb(225, 225, 225);position: absolute;left: 51%;top: 10px;"></div>
      <van-dropdown-item v-model="value1" :options="option1" @change="changeleft" />
      <van-dropdown-item v-model="value2" :options="option2" @change="changeright" />
    </van-dropdown-menu>
    <div v-show="datalist.length == 0"  class="wudingdan" >
        <van-icon name="description"/>
        <p>亲,暂无相关数据哦</p>
    </div>
    <van-list v-show="datalist.length != 0" v-model="loading" :finished="finished" finished-text="没有更多了" @load="ShopList">
      <div class="food_content" v-for="(itme,index) in datalist" :key="index" @click="shoppingDetails(itme.shpSN)">
        <div class="system_img"><img :src="itme.Cover"></div>
        <div class="system_content">
          <p class="theme">{{itme.Name}}</p>
          <div class="minute">
            <span class="minute_minute">{{itme.Score}}分</span>
          </div>
          <div class="tired">
            <div class="title">
              <van-tag color="#46d0ca" v-for="(data,index) in itme.Tags" :key='index' plain style="border: 1px solid;">{{data}}</van-tag>
            </div>
            <span>距离{{itme.Distance}}米</span>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
  import Swiper from 'swiper';
  import 'swiper/dist/css/swiper.min.css';
  import {
    ShopList
  } from '@/api/home.js'
  export default {

    data() {
      return {
        clintHeigth: '', //获取页面高度
        input: '', //搜索
        datalist: [], //数据数组
        jinweilng: localStorage.getItem('Jingweilng'), //取经纬度
        jinweilat: localStorage.getItem('Jingweilat'), //取经纬度
        loading: false, //控制上拉加载的加载动画
        finished: false, //控制在页面往下移动到底部时是否调用接口获取数据
        totalPage: 0,
        pageNumber: 0, //自定义一个页数变量
        value1: 0,
        value2: '不限',
        option1: [{
            text: '推荐排序',
            value: 0
          },
          {
            text: '离我最近',
            value: 1
          },
          {
            text: '人气最高',
            value: 2
          },

        ],
        option2: [{
            text: '不限',
            value: '不限',
          },
          {
            text: '超市&便利店',
            value: '超市&便利店',
          },
          {
            text: '服饰鞋包',
            value: '服饰鞋包',
          },
          {
            text: '综合商城',
            value: '综合商城',
          },
          {
            text: '食品药品',
            value: '食品药品',
          },
          {
            text: '水果生鲜',
            value: '水果生鲜',
          },
          {
            text: '本地特产',
            value: '本地特产',
          },
          {
            text: '其他',
            value: '其他',
          },
        ]
      }
    },
    mounted() {
      this.clientHeight = `${document.documentElement.clientHeight}` //document.body.clientWidth;
      // console.log(this.clientHeight);
      // let dd = 100;
      this.$refs.homePage.style.minHeight = this.clientHeight + 'px';
      this.ShopList();
    },
    methods: {
      onClickLeft() {
        this.$router.go(-1);
      },
      shoppingDetails(shpSN) {
        this.$router.push({
          path: "/shopping/shoppingDetails",
          query: {
            shpSN: shpSN,
          }
        })
      },
      ShopList() {
        let data = {
          "PageNo": this.pageNumber + 1, //页码
          "Lng": this.jinweilng, //经纬度
          "Lat": this.jinweilat,
          "Type": 1,
          "Keywords":this.input,
          "SortType": this.value1,
          // "Tags":this.value2,
        }
        ShopList(data).then(res => {
          console.log(res)
          if (res.List.length > 0) {
            this.datalist = this.datalist.concat(res.List);
          } else {
            this.datalist = res.List
          }
          this.totalPage = res.PageCount;
          // this.datalist = res.List
          this.loading = false;
          this.pageNumber++;
          if (this.pageNumber >= this.totalPage) {
            this.finished = true;
          }
        })
      },
      inputdata(value) {
        console.log(1)
        this.datalist = []
        this.pageNumber = 0;
        this.ShopList();
        this.$forceUpdate();
      },
      changeleft(value) {
        this.datalist = []
        this.pageNumber = 0;
        this.ShopList();
        this.$forceUpdate();
      },
      changeright(value) {
        console.log(1)
        this.datalist = []
        this.pageNumber = 0;
        this.ShopList();
        this.$forceUpdate();
      },
    }
  }
</script>

<style lang="scss">
  .food {
    background: white;

    .bj {
      .van-icon {
        color: white !important;

      }
    }

    .van-nav-bar {

      // border-bottom: 1px solid #e4e4e4;
      .van-nav-bar__left {
        .van-icon {
          color: #46d0ca;
          font-size: 18px;
        }
      }

      .van-nav-bar__title {
        color: #000000;
      }
    }

    .input {
      width: 100%;
      position: fixed;
      display: flex;
      justify-content: center;
      align-items: center;
      // margin-top: 46px;
      height: 50px;
      top: 46px;
      background: #46d0ca;
      z-index: 999;
      .van-search {
        width: 100% !important;
        height: 100%;
        // border: 1px solid #46d0ca;
        padding: 0px;
        border-radius: 30px;
        // margin: 5px auto;
        border: none;

        div {
          border-radius: 30px;
        }
      }
    }

    .van-dropdown-menu {
      width: 100%;
      top: 96px;
      position: fixed;
      background: #eee;
      z-index: 999;

      // .van-dropdown-menu__title{
      //   color: #5C5C5C !important;
      // }
    }

    .food_content {
      width: 100%;
      height: 130px;
      padding: 10px;
      display: flex;
  	  border-bottom: 1px solid #f0f0f0;
  	  margin-bottom: 10px;
      .system_img {
        width: 30%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;

        img {
          width: 100%;
        }
      }

      .system_content {
        width: 70%;

        .theme {
          width: 100%;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          color: rgb(40, 40, 40);
          padding: 2px 10px;
          font-size: 18px;
        }

        .minute {
          font-weight: 400;
          padding: 10px;

          .minute_minute {
            font-size: 20px;
            color: #46d0ca;
            // padding: 10px;
          }
        }

        .tired {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 10px;

          .title {
            .van-tag {
              margin: 2px;
            }
          }
        }
      }
    }
  }
</style>
